﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using BCDto.TMS.VehicleSuiteBusinessConfig;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.TMS.VehicleSuiteBusinessConfig;
using BCCommon.TMS.Transport;

namespace BCTMSRESTful.Controllers.Management.TMS.VehicleSuiteBusinessConfig
{
    /// <summary>
    /// 车辆套餐业务配置
    /// </summary>
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class VehicleSuiteBusinessConfigController : ManagementBaseController
    {
        private readonly IVehicleSuiteBusinessConfigService vehicleSuiteBusinessConfigService;

        public VehicleSuiteBusinessConfigController(IVehicleSuiteBusinessConfigService vehicleSuiteBusinessConfigService)
        {
            this.vehicleSuiteBusinessConfigService = vehicleSuiteBusinessConfigService;
        }

        #region 添加车辆套餐业务配置
        /// <summary>
        ///  添加车辆套餐业务配置
        /// </summary>
        /// <param name="requestDto">车辆套餐业务配置信息</param>
        /// <response code="201">添加车辆套餐业务配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加车辆套餐业务配置")]
        [ProducesResponseType(typeof(VehicleSuiteBusinessConfigDto), 201)]
        public IActionResult Post(
            [FromBody] VehicleSuiteBusinessConfigRequestDto requestDto)
        {
            var result = this.vehicleSuiteBusinessConfigService.Add(this.Admin,requestDto);
            return StatusCode((int)HttpStatusCode.Created, result);
        }
        #endregion

        #region 修改车辆套餐业务配置
        /// <summary>
        ///  修改车辆套餐业务配置
        /// </summary>
        /// <param name="vehicleSuiteBusinessConfigId">车辆套餐业务配置Id</param>
        /// <param name="requestDto">车辆套餐业务配置信息</param>
        /// <response code="200">修改车辆套餐业务配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{vehicle_suite_business_config_id}")]
        [Log("修改车辆套餐业务配置")]
        [ProducesResponseType(typeof(VehicleSuiteBusinessConfigDto), 200)]
        public IActionResult Put([FromRoute(Name = "vehicle_suite_business_config_id")] int vehicleSuiteBusinessConfigId, [FromBody] VehicleSuiteBusinessConfigRequestDto requestDto)
        {
            VehicleSuiteBusinessConfigPutDto putDto = requestDto.As<VehicleSuiteBusinessConfigPutDto>();
            putDto.VehicleSuiteBusinessConfigId = vehicleSuiteBusinessConfigId;
            return StatusCode((int)HttpStatusCode.OK, this.vehicleSuiteBusinessConfigService.Update(this.Admin, putDto));
        }
        #endregion

        #region 获取车辆套餐业务配置
        /// <summary>
        ///  获取车辆套餐业务配置
        /// </summary>
        /// <param name="vehicleSuiteBusinessConfigId">车辆套餐业务配置Id</param>
        /// <response code="200">获取车辆套餐业务配置</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{vehicle_suite_business_config_id}")]
        [ProducesResponseType(typeof(VehicleSuiteBusinessConfigDto), 200)]
        public IActionResult Get([FromRoute(Name = "vehicle_suite_business_config_id")] int vehicleSuiteBusinessConfigId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.vehicleSuiteBusinessConfigService.Get(vehicleSuiteBusinessConfigId));
        }
        #endregion

        #region 获取车辆套餐业务配置列表
        /// <summary>
        ///  获取车辆套餐业务配置列表
        /// </summary>
        /// <response code="200">获取车辆套餐业务配置列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(IEnumerable<VehicleSuiteBusinessConfigDto>), 200)]
        public IActionResult Get()
        {
            return StatusCode((int)HttpStatusCode.OK, this.vehicleSuiteBusinessConfigService.GetList(this.Admin.AgentRecord.AgentRecordId));
        }
        #endregion

        #region 获取车辆套餐业务配置（分页）
        /// <summary>
        ///  获取车辆套餐业务配置（分页）
        /// </summary>
        /// <param name="suiteBusinessName">套餐业务名称</param>
        /// <param name="suiteBusinessType">套餐业务类型</param>
		/// <param name="provinceCode">省份编码</param>
		/// <param name="cityCode">城市编码</param>
		/// <param name="countyCode">区县编码</param>
        /// <param name="enabled">启用/禁用</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取车辆套餐业务配置（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<VehicleSuiteBusinessConfigDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "suite_business_name")] string suiteBusinessName,
            [FromQuery(Name = "suite_business_type")] VehicleSuiteBusinessType? suiteBusinessType,
            [FromQuery(Name = "province_code")] string provinceCode,
            [FromQuery(Name = "city_code")] string cityCode,
            [FromQuery(Name = "county_code")] string countyCode,
            [FromQuery(Name = "enabled")] bool? enabled,
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "sort_name")] string sortName,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "index")] int index = 1,
            [FromQuery(Name = "size")] int size = 10)
        {
            long? agentRecordId = null;
            if (this.Admin.AgentRecord != null)
            {
                agentRecordId = this.Admin.AgentRecord.AgentRecordId;
            }
            return StatusCode((int)HttpStatusCode.OK, this.vehicleSuiteBusinessConfigService.Query(agentRecordId, suiteBusinessName, provinceCode,cityCode,countyCode, suiteBusinessType,enabled, start, end, sortName, ascending, index, size));
        }
        #endregion

        #region 启用/禁用车辆套餐业务配置
        /// <summary>
        ///  启用/禁用车辆套餐业务配置
        /// </summary>
        /// <param name="vehicleSuiteBusinessConfigId">车辆套餐业务配置Id</param>
        /// <param name="enabled">是否启用</param>
        /// <response code="204">启用/禁用车辆套餐业务配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("[action]/{vehicle_suite_business_config_id}/{enabled}")]
        [Log("启用/禁用车辆套餐业务配置")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Enabled([FromRoute(Name = "vehicle_suite_business_config_id")] int vehicleSuiteBusinessConfigId,
            [FromRoute(Name = "enabled")] bool enabled)
        {
            if (enabled)
            {
                this.vehicleSuiteBusinessConfigService.Enabled(this.Admin,vehicleSuiteBusinessConfigId);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
            else
            {
                this.vehicleSuiteBusinessConfigService.Disabled(this.Admin,vehicleSuiteBusinessConfigId);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
        }
        #endregion
    }
}

